//
//  SNHomeCollectionViewCell.m
//  project
//
//  Created by 张淋 on 2019/6/22.
//  Copyright © 2019 黄建华. All rights reserved.
//

#import "SNHomeCollectionViewCell.h"

@implementation SNHomeCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.backView.layer.borderWidth = 0.5;
    self.backView.layer.borderColor = SNCOLORGRAYLINE.CGColor;
}

-(void)configWithModel:(SNHomeModel *)model edit:(BOOL)edit {
    
    _editBtn.hidden = !edit;
    
    if (model.add) {
        _editBtn.imageNormal = @"mainAdd";
    } else {
        _editBtn.imageNormal = @"mainDelete";
    }
    
    self.valueLab.text = model.value;
    self.valueLab.font          = SNFONT(FitFont(20.0));
    self.valueLab.textAlignment = NSTextAlignmentCenter;
    
    self.valueDesLab.text = model.valueDes;
    self.valueDesLab.font          = SNSFONT(FitFont(11.0));
    self.valueDesLab.textColor     = [UIColor colorFromHex:0x767676];
    
    self.hvAgLab.text = model.hrAvg;
    self.hvAgLab.font          = SNSFONT(FitFont(11.0));
    self.hvAgLab.textColor     = [UIColor colorFromHex:0x767676];
    
    self.funtionTitleLab.text = model.functionTitle;
    self.funtionTitleLab.textAlignment = NSTextAlignmentCenter;
    self.funtionTitleLab.font          = SNFONT(FitFont(14.0));
    
    self.imageView.image = [UIImage image:model.imageName];
    
    //SNHomeModel 功能标识(0.健康日报 1.睡眠记录  2.运动模式 3.体检 4.心率记录  5.血压记录 6.血氧记录)
    int tag = model.tag;
    if (tag == 1) {
        [self.valueLab setAttributedText:[SN_PublicClass label1With:self.valueLab.text withFontsize:15.0 withChangeText1:SN_Text(@"h") withChangeText2:SN_Text(@"mins")]];
    }
    if (tag == 4) {
        [self.valueLab setAttributedText:[SN_PublicClass label1With:self.valueLab.text withFontsize:15.0 withChangeText1:@"" withChangeText2:@"bpm"]];
    }
    if (tag == 5) {
        [self.valueLab setAttributedText:[SN_PublicClass label1With:self.valueLab.text withFontsize:15.0 withChangeText1:@"" withChangeText2:@"mmHg"]];
    }
    if (tag == 2) {
        self.valueLab.font          = SNSFONT(FitFont(11.0));
        self.valueLab.textColor     = [UIColor colorFromHex:0x767676];
        self.hvAgLab.text = model.valueDes;
        if (![model.hrAvg isEqualToString:@""]) {
            self.valueDesLab.text = [model.hrAvg stringByAppendingString:@"bpm"];
        }
    }

    
    _model = model;
}

- (IBAction)editAction:(UIButton *)sender {
    if (self.block) {
        self.block(_model);
    }
}

@end
